//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    userInfo: {},
    domain:app.globalData.domain,
    System_Img_Url:app.globalData.System_Img_Url
  },

  onLoad: function () {

    var that = this
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function(userInfo){
      //更新数据
      that.setData({
        userInfo:userInfo
      })
      //发送用户信息，没有则添加，不同则修改
    //  console.log(userInfo)
 //   console.log(wx.getStorageSync('openid'))
  //  return
      wx.request({
        url:app.globalData.urls,
        data:{
          GetTypes:'UserEdit',
          user_name:userInfo.nickName,
          user_img:userInfo.avatarUrl,
          openid:wx.getStorageSync('openid')
        },
        success:function(res){
       //   console.log(res.data)
        }
      })
    })
    this.Get_Album_Count()
    this.Get_Flower_Count()
    this.Get_Collect_Count()
    this.Get_Albums(1)

  },

//删除相册
  Album_Del(e){

    var that = this
    wx.showModal({
      title:'删除相册？',
      content:'确认删除？',
      success:function(res){
        if(!res.confirm){
          return;
        }else{
            var aid = e.currentTarget.dataset.aid
            var oid = wx.getStorageSync('openid')
            wx.request({
              url:app.globalData.urls,
              data:{
                'GetTypes':'Album_Dels',
                'aid':aid,
                'oid':oid
              },
              success:function(res){
                //console.log(res.data)
                that.Get_Albums(that.data.album_info.Pnow)
              }
            })
        }
      }
    });
  },


//发布新相册
  Album_Add(){
    wx.setStorageSync('album_info_s',null)
    wx.redirectTo({
      url:'../album_add2/album_add2',
    })
  },

//跳转到图片列表
  Jump_Pics(e){
    var idx = e.currentTarget.dataset.index
    var obj = this.data.album_info
    wx.setStorageSync('album_info_s',obj.DataList[idx])
    wx.redirectTo({
   // wx.navigateTo({
      url:'../album_add2/album_add2?'
    })
  },





//获取用户的所有相册
  Get_Albums(pnow){
    var t = this
   // console.log(wx.getStorageSync('openid'))
    wx.request({
      url:app.globalData.urls,
      data:{
        GetTypes:'Get_User_Album',
        openid:wx.getStorageSync('openid'),
        pnow:pnow
      },
      success:function(res){
      //  console.log(res.data)
        if(res.data == 'err'){
          album_info=null
        }
      //  console.log(res.data)
        t.setData({
          album_info:res.data
        })
      }
    })
  },

//获取用户的相册数
  Get_Album_Count(){
    var t = this
    wx.request({
      url:app.globalData.urls,
      data:{
        GetTypes:'Get_User_Album_Count',
        openid:wx.getStorageSync('openid')
      },
      success:function(res){
     //   console.log(res.data)
        t.setData({
          album_count:res.data
        })
      }
    })
  },


//获取用户被赞总数
  Get_Flower_Count(){
 //  console.log(wx.getStorageSync('openid'))
    var t = this
    wx.request({
      url:app.globalData.urls,
      data:{
        GetTypes:'Get_User_All_Album_Flower_Count',
        openid:wx.getStorageSync('openid')
      },
      success:function(res){
       // console.log(res.data)
        t.setData({
          flower_count:res.data
        })
      }
    }) 
  },

//获取用户相册被收藏总数
  Get_Collect_Count(){
    var t = this
    wx.request({
      url:app.globalData.urls,
      data:{
        GetTypes:'Get_Album_All_Collect_Count',
        openid:wx.getStorageSync('openid')
      },
      success:function(res){
        t.setData({
          collect_count:res.data
        })
      }
    }) 
  },



})




